;; File              : init-ui.el
;; Author            : gotpl <631707329@qq.com>
;; Date              : 2024-05-22 15:37:58
;; Last Modified Date: 2024-05-22 15:37:58
;; Last Modified By  : gotpl <631707329@qq.com>
;; -----
;;; init-ui.el -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2023 gotpl
;;
;; Author: gotpl <631707329@qq.com>
;; Maintainer: gotpl <631707329@qq.com>
;; Created: 七月 27, 2023
;; Modified: 七月 27, 2023
;; Version: 0.0.1
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp
;; Homepage: https://github.com/gotpl/init-ui
;; Package-Requires: ((emacs "24.3"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;;
;;
;;; Code:

(setq inhibit-startup-screen t
      inhibit-startup-message t
      initial-buffer-choice nil
      initial-major-mode (quote fundamental-mode))
(tool-bar-mode -1)
(menu-bar-mode -1)
(if (fboundp 'scroll-bar-mode)
    (scroll-bar-mode -1)
  (setq scroll-bar-mode -1))


(add-to-list 'default-frame-alist
             '(font . "Maple Mono NF CN 12"))

;; 相对行号
(setq display-line-numbers-type 'relative)
(global-display-line-numbers-mode t)

;; emacs 29 默认开启
(setq show-paren-when-point-inside-paren t
      show-paren-when-point-in-periphery t)
;; Highlight parenthesises
;; (defun load-paren! ()
;;   (require 'paren)
;;   ;; (show-paren-mode)
;;   )
;; (use-package paren
;;   :ensure nil
;;   :hook (emacs-startup. load-paren!)
;;   :custom
;;   (show-paren-when-point-inside-paren t)
;;   (show-paren-when-point-in-periphery t))

(use-package simple
  :ensure nil
  :custom
  ;; show line/column/filesize in modeline
  (line-number-mode t)
  (column-number-mode t)
  (size-indication-mode t)
  ;; No visual feedback on copy/delete.
  (copy-region-blink-delay 0)
  (delete-pair-blink-delay 0)
  ;; confusing if no fringes (GUI only).
  (visual-line-fringe-indicators '(nil right-curly-arrow))
  ;; don't save current clipboard text before replacing it
  (save-interprogram-paste-before-kill nil)
  ;; eliminate duplicates
  (kill-do-not-save-duplicates t)
  ;; include '\n' when point starts at the beginning-of-line
  (kill-whole-line t)
  ;; show cwd when `shell-command' and `async-shell-command'
  (shell-command-prompt-show-cwd t)
  ;; show the name of character in `what-cursor-position'
  (what-cursor-show-names t)
  ;; List only applicable commands.
  ;;
  ;; ``` elisp
  ;; (defun foo ()
  ;;   (interactive nil org-mode)
  ;;   (message "foo"))
  ;; ```
  ;;
  ;; M-x foo should only be available in `org-mode` or modes derived from `org-mode`.
  (read-extended-command-predicate #'command-completion-default-include-p))

;; Highlight current line in GUI
(defun load-hl-line! ()
  (require 'hl-line)
  (global-hl-line-mode)
  )
(use-package hl-line
  :ensure nil
  ;; :defer t
  ;; :when (display-graphic-p)
  :hook (emacs-startup . load-hl-line!)
  )

;; (use-package tokyo-theme
;;   :ensure (:host github :repo "rawleyfowler/tokyo-theme.el"))

(use-package doom-themes
  ;; :hook (emacs-startup . load-doom-themes!) ;;  
  :ensure t
  :config
  (load-theme 'doom-solarized-light t)
  ;; (if (display-graphic-p)
      ;; (load-theme 'doom-one t)
  ;;   (load-theme 'spacemacs-dark t))
  (doom-themes-org-config)
  )

;; (use-package flucui-themes
;;   :config
;;   (load-theme 'flucui-dark t))

;; (use-package keycast
;;   ;; :init
;;   ;; (add-to-list 'global-mode-string '("" keycast-mode-line))
;;   ;; :hook (doom-modeline-mode . keycast-mode)
;;   :config
;;   (keycast-mode-line-mode t)
;;   ;; (keycast-log-mode t)
;;   ;; (keycast-header-line-mode t)
;;   )


(defun load-doom-modeline! ()
  (require 'doom-modeline)
  
  )
(use-package doom-modeline
  ;; :hook (emacs-startup . load-doom-modeline!)
  :custom
  (doom-modeline-env-version t)
  (doom-modeline-irc nil)
  (doom-modeline-mu4e nil)
  (doom-modeline-gnus nil)
  (doom-modeline-github nil)
  (doom-modeline-persp-name nil)
  (doom-modeline-unicode-fallback t)
  (doom-modeline-enable-word-count nil)
  :config
  (doom-modeline-mode 1)

  )
;; (add-hook 'after-init-hook 'load-doom-modeline!)

;; (use-package winum
;;   :bind (
;;          ("M-0" . 'winum-select-window-0-or-10)
;;          ("M-1" . 'winum-select-window-1)
;;          ("M-2" . 'winum-select-window-2)
;;          ("M-3" . 'winum-select-window-3)
;;          ("M-4" . 'winum-select-window-4)
;;          ("M-5" . 'winum-select-window-5)
;;          ("M-6" . 'winum-select-window-6)
;;          ("M-7" . 'winum-select-window-7)
;;          ("M-8" . 'winum-select-window-8)
;;          ("M-9" . 'winum-select-window-9))
;;   :config
;;   (winum-mode t)
;;   )

;; ;; (use-package all-the-icons
  
;; ;;   :when (display-graphic-p)
;; ;;   :demand t)

;; ;; (use-package nerd-icons
;; ;;   :ensure (:host github :repo "rainstormstudio/nerd-icons.el")
;; ;;   :config
;; ;;   (setq nerd-icons-font-family "CaskaydiaCove Nerd Font Mono"))

;; 彩虹括号
(use-package rainbow-delimiters
  :hook (prog-mode . rainbow-delimiters-mode)
  )
;; 执行shell命令显示颜色
(defun load-xterm-color! ()
  ;; (message "load-xterm-color")
  ;; (require 'xterm-color)
  ;; Disable font-locking in this buffer to improve performance
  ;; (font-lock-mode -1)
  ;; ;; Prevent font-locking from being re-enabled in this buffer
  ;; (make-local-variable 'font-lock-function)
  ;; (setq font-lock-function (lambda (_) nil))
  (setq compilation-environment '("TERM=xterm-256color"))

  (defun my/advice-compilation-filter (f proc string)
    (message (process-name proc))
    (if (string= (process-name proc) "color-rg") ;; 防止color-rg也做这个操作报错
      (funcall f proc string)
    (funcall f proc (xterm-color-filter string)))
    )

  (advice-add 'compilation-filter :around #'my/advice-compilation-filter)
  (add-hook 'comint-preoutput-filter-functions 'xterm-color-filter nil t)
  )
(use-package xterm-color
  :after projectile
  :config
  (load-xterm-color!)
  )

;; (defun xterm-color-colorize-shell-command-output ()
;;   "Colorize `shell-command' output."
;;   (let ((bufs
;;          (seq-remove
;;           (lambda (x)
;;             (not (or (string-prefix-p " *Echo Area" (buffer-name x))
;;                      (string-prefix-p "*Shell Command" (buffer-name x))
;;                      ;; (string-prefix-p "*compilation*" (buffer-name x))
;;                      )))
;;           (buffer-list))))
;;     (dolist (buf bufs)
;;       (with-current-buffer buf
;;         (xterm-color-colorize-buffer)))))

;; (defun xterm-color-colorize-shell-command-output-advice (proc &rest rest)
;;   (xterm-color-colorize-shell-command-output))

;; (advice-add 'shell-command :after #'xterm-color-colorize-shell-command-output-advice)

;; ;; compile彩色输出
;; (use-package fancy-compilation
;;   :ensure (:repo "https://github.com/emacsmirror/fancy-compilation")
;;   :config
;;   (with-eval-after-load 'compile
;;     (fancy-compilation-mode)))

;; (advice-remove 'shell-command #'xterm-color-colorize-shell-command-output-advice)
;; (advice-remove 'shell-command #'ansi-color-apply-on-minibuffer-advice)

;; (require 'ansi-color)

;; (defadvice display-message-or-buffer (before ansi-color activate)
;;   "Process ANSI color codes in shell output."
;;   (let ((buf (ad-get-arg 0)))
;;     (and (bufferp buf)
;;          (string= (buffer-name buf) "*Shell Command Output*")
;;          (with-current-buffer buf
;;            (ansi-color-apply-on-region (point-min) (point-max))))))
;; (require 'ansi-color)

;; (defadvice display-message-or-buffer (before ansi-color activate)
;;   "Process ANSI color codes in shell output."
;;   (let ((buf (ad-get-arg 0)))
;;     (and (bufferp buf)
;;          (string= (buffer-name buf) "*Shell Command Output*")
;;          (with-current-buffer buf
;;            (ansi-color-apply-on-region (point-min) (point-max))))))
;; (use-package centaur-tabs
;;   :ensure (:host github :repo "ema2159/centaur-tabs")
;;   :hook
;;   (dashboard-mode . centaur-tabs-local-mode)
;;   (term-mode . centaur-tabs-local-mode)
;;   (calendar-mode . centaur-tabs-local-mode)
;;   (org-agenda-mode . centaur-tabs-local-mode)
;;   :config
;;   (centaur-tabs-mode t)
;;   (setq centaur-tabs-modified-marker "")
;;   (setq centaur-tabs-set-close-button nil)
;;   (setq centaur-tabs-style "bar")
;;   (setq centaur-tabs-set-icons t)
;;   (setq centaur-tabs-gray-out-icons 'buffer)
;;   (setq centaur-tabs-set-modified-marker t)
;;   (define-key evil-normal-state-map (kbd "C-l") 'centaur-tabs-forward)
;;   (define-key evil-normal-state-map (kbd "C-h") 'centaur-tabs-backward)
;;   (defun centaur-tabs-hide-tab (x)
;;   "Do no to show buffer X in tabs."
;;     (let ((name (format "%s" x)))
;;       (or
;;       ;; Current window is not dedicated window.
;;       (window-dedicated-p (selected-window))

;;       ;; Buffer name not match below blacklist.
;;       (string-prefix-p "*epc" name)
;;       (string-prefix-p "*helm" name)
;;       (string-prefix-p "*Helm" name)
;;       (string-prefix-p "*Compile-Log*" name)
;;       (string-prefix-p "*lsp" name)
;;       (string-prefix-p "*company" name)
;;       (string-prefix-p "*Flycheck" name)
;;       (string-prefix-p "*tramp" name)
;;       (string-prefix-p " *Mini" name)
;;       (string-prefix-p "*help" name)
;;       (string-prefix-p "*straight" name)
;;       (string-prefix-p " *temp" name)
;;       (string-prefix-p "*Help" name)
;;       (string-prefix-p "*mybuf" name)

;;       ;; Is not magit buffer.
;;       (and (string-prefix-p "magit" name)
;;             (not (file-name-extension name)))
;;       ))))

(provide 'init-ui)
;;; init-ui.el ends here
